﻿using System;
using System.Collections.Generic;
using System.Text;
using RobotControl.Tools.UserControls;

namespace LocalizationTest.Tools
{
  class DebugKeyTool
  {
    private static NameSpaceTreeView2 nameSpaceTreeView;

    public static void SetNameSpaceTreeView(NameSpaceTreeView2 nst)
    {
      nameSpaceTreeView = nst;
    }

    static public void ToggleKey(string id)
    {
      if(nameSpaceTreeView.NodeIDs.ContainsKey(id))
      {
        nameSpaceTreeView.NodeIDs[id].isChecked = !nameSpaceTreeView.NodeIDs[id].isChecked;
        nameSpaceTreeView.SetCheck(id, nameSpaceTreeView.NodeIDs[id].isChecked);
      }
    }
    static public bool IsActive(string id)
    {
      nameSpaceTreeView.AddOrConfirmValue(id);
      return nameSpaceTreeView.NodeIDs[id].isChecked;
    }

    public static void Reset()
    {
      nameSpaceTreeView.Clear();
    }
    public static void DisableAll()
    {
      Dictionary<string, LocalizationTest.Tools.NameSpaceTreeView2.NodeProperties> copiedNodeIDs = new Dictionary<string, LocalizationTest.Tools.NameSpaceTreeView2.NodeProperties>();
      foreach (string key in nameSpaceTreeView.NodeIDs.Keys)
      {
        copiedNodeIDs[key] = new NameSpaceTreeView2.NodeProperties(false, nameSpaceTreeView.NodeIDs[key].isKnown);
      }
      nameSpaceTreeView.NodeIDs = copiedNodeIDs;
    }

    public static string GetState()
    {
      string stateString = "";
      foreach (string key in nameSpaceTreeView.NodeIDs.Keys)
      {
        if (nameSpaceTreeView.NodeIDs[key].isChecked) stateString += key + ";";
      }
      return stateString;
    }
    public static void SetState(string stateString)
    {
      DisableAll();
      string[] parts = stateString.Split(';');
      foreach (string part in parts)
      {
        nameSpaceTreeView.SetCheck(part, true);
      }
      nameSpaceTreeView.UpdateTree();
      nameSpaceTreeView.TreeView.ExpandAll();
    }
  }
}
